<extend name="Base/base" />
<block name="button">	
	<button class="btn btn-primary" type="submit" form="form"><i class="fa fa-save"></i> {:L('text_save')}</button>
</block>
<block name="body">
	<if condition="$msg">
		<div class="alert alert-danger alert-dismissible fade in" role="alert">
		    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
		     {$msg.warning}
		</div>
	</if>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h4><i class="fa fa-pencil fa-fw"></i>  {$heading_title}</h4>
		</div>
		<div class="panel-body">
			<form action="" method="post" id="form" class="form-horizontal">
				<ul class="nav nav-tabs">
					<li class="active"><a href="#tab-general" data-toggle="tab">{:L('tab_general')}</a></li>
					<li><a href="#tab-permission" data-toggle="tab">{:L('tab_permission')}</a></li>
					<li><a href="#tab-navigation" data-toggle="tab">{:L('tab_navigation')}</a></li>
				</ul>
				<div class="tab-content">
					<div class="tab-pane active" id="tab-general">
						<div class="form-group required">
							<label for="input-name" class="col-sm-2 control-label">{:L('entry_name')}</label>
							<div class="col-sm-10">
								<input type="text" value="{$user_group.name}" placeholder="{:L('entry_name')}" name="name" class="form-control" id="input-name">
								<if condition="isset($msg['name'])">
								{:danger_msg($msg['name'])}
								</if>
							</div>						
						</div>
						<div class="form-group">
							<label for="input-status" class="control-label col-sm-2">{:L('text_status')}</label>
							<div class="col-sm-10">
								<select name="status" id="input-status" class="form-control">
									<option value="1">{:L('text_enabled')}</option>
									<option <if condition="isset($user_group['status']) && ($user_group['status'] eq 0)">selected</if> value="0">{:L('text_disabled')}</option>						
								</select>
							</div>
						</div>
					</div>
					<div class="tab-pane" id="tab-permission">
						<table class="table table-bordered table-striped">
							<thead>
								<tr>
									<th style="width:150px;">{:L('column_name')}</th>
									<th>{:L('column_action')}</th>
								</tr>
									
							</thead>
							<tbody>
								<foreach name="permissions" item="perm">
									<tr>
										<th><label><input type="checkbox" name="permission[]" value="{$perm.permission_id}" {:in_array($perm['permission_id'],$user_group['permission'])?'checked':''}>  {$perm.title}</label></th>
										<td class="permission-list">
											<foreach name="perm['child']" item="child">
												<label><input type="checkbox" name="permission[]" {:in_array($child['permission_id'],$user_group['permission'])?'checked':''} value="{$child.permission_id}"> {$child.title}</label>
											</foreach>
										</td>
									</tr>
								</foreach>
							</tbody>
						</table>
					</div>
					<div class="tab-pane" id="tab-navigation">
						<table class="table table-bordered table-striped">
							<thead>
								<tr>
									<th style="width:150px;">{:L('column_name')}</th>
									<th>{:L('column_action')}</th>
								</tr>
									
							</thead>
							<tbody>
								<foreach name="navigations" item="nav">
									<tr>
										<th><label><input type="checkbox" name="navigation[]" value="{$nav.menu_id}" {:in_array($nav['menu_id'],$user_group['navigation'])?'checked':''}>  {$nav.title}</label></th>
										<td class="navigation-list">
											<foreach name="nav['child']" item="child">
												<label><input type="checkbox" name="navigation[]" {:in_array($child['menu_id'],$user_group['navigation'])?'checked':''} value="{$child.menu_id}"> {$child.title}</label>
												<foreach name="child['child']" item="sub">
													<label><input type="checkbox" name="navigation[]" {:in_array($sub['menu_id'],$user_group['navigation'])?'checked':''} value="{$sub.menu_id}"> {$sub.title}</label>
												</foreach>
											</foreach>
										</td>
									</tr>
								</foreach>
							</tbody>
						</table>
					</div>
				</div>
				
			</form>
			
		</div>
		
	</div>
</block>
<block name="script">
	<script type="text/javascript">
		$("tr th input[type='checkbox']").on('click',function(){
			$(this).parents('tr').find('td').find('input[type="checkbox"]').prop('checked',this.checked);
		});
	</script>
</block>
